<template>
  <div>
    <tableComponents
      :pagination="{ currentPage, pageSize, total: list.all_num }"
      @handleCurrentChange="handleCurrentChange"
      @handleSizeChange="handleSizeChange"
      @sendUserSearch="receive_search"
      :searchData="userSearchData"
      :isHaveExport="false"
      :isHaveAdd="false"
      @toAdd="add_data"
      :isShow="false"
      :isHavePagination="false"
    >
      <template v-slot:table>
        <!-- :data="list.data" -->
        <el-table
          ref="multipleTable"
          :data="list"
          stripe
          v-loading="loading"
          header-row-class-name="head_color"
          tooltip-effect="dark"
          style="width: 99.8%"
        >
          <!-- <el-table-column type="selection" class="tc" width="35"></el-table-column> -->
          <el-table-column label="会员账号" min-width="120">
            <template slot-scope="scope">
              <div class="user_table">
                <small>{{scope.row.username}}</small>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="会员昵称" min-width="120">
            <template slot-scope="scope">
              <div class="user_table">
                <small>{{scope.row.nickname || '----'}}</small>
              </div>
            </template>
          </el-table-column>

          <el-table-column width="300" label="操作">
            <template slot-scope="scope">
              <el-button size="mini" @click="add_ployee(scope.row.id)" type="success">添加为员工</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
      <!-- <template v-slot:footerLeft>
        <a class="aBtn aBtn_1 aBtn_lan2" @click="delSelection()">删除</a>
      </template>-->
    </tableComponents>
    <el-dialog
      :close-on-click-modal="false"
      title="员工设置"
      :append-to-body="true"
      width="500px"
      :visible.sync="dialogeditVisible"
    >
      <div style="display:flex;    flex-direction: column;">
        <div style="width:100%;display:flex;justify-content: center">
          <label style="width:100%">
            员工权重
            <el-input style="margin:5px 0;" v-model="add_params.staff_weight" placeholder="请输入员工权重"></el-input>
          </label>
        </div>
        <div style="display:flex;justify-content: flex-end;">
          <el-button type="primary" @click="comfirm_add" size="mini">添加员工</el-button>
        </div>
      </div>
    </el-dialog>
    <keep-alive>
      <component
        :is="current"
        :show="shows"
        :isAll="true"
        showType="list"
        @sendShop="getSend"
        @isshow="getShow"
      ></component>
    </keep-alive>
  </div>
</template>
<script>
import uploadpic from "@/components/page/pic/up_pic"; //上传图片
import { doTaskList } from "@/assets/js/searchData/searchData"; //引入搜索的数据
import xzShop from "@/components/currency/xz_shop.vue";
export default {
  data() {
    return {
      piclink: [],
      shows: true,
      current: "",
      shopinfo: {
        title: "",
      },
      userSearchData: doTaskList,
      dialogeditVisible: false,
      // 输入值库
      edit_form: {
        piclink: "",
      },
      // editMsg: {},
      createTime: [],
      formVideo: {
        uid: "",
        uri: "",
        is_recommend: 0,
        // title: "",
        duration: "",
        start_time: "",
        stop_time: "",
      },
      dialogaddVisible: false,
      playurl: "",
      is_edit: false,
      dialogFormVisible: false,
      live_single: {
        piclink: "",
      },
      current: "",
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      row: {},
      showCity: true,
      // 头像
      dialogImageUrl: "",
      dialogVisible: false,
      // 分类
      edmsgs: {},
      siteid: "",
      siteobj: {},
      changePriceFlag: false,
      nowPlace: "",
      timeMsg: [],
      wanna_del: "",
      multipleSelection: [], //多选框玄宗的值
      add_params: {},
    };
  },
  components: {
    uploadpic,
    xzShop,
  },
  mounted() {
    this.get_users();
  },
  methods: {
    add_ployee(id) {
      this.add_params.id = id;
      this.dialogeditVisible = true;
    },
    comfirm_add() {
      let params = this.add_params;
      this.$api.getCrm.add_ployee(params).then((res) => {
        if (res.data.code == 200) {
          this.$swal("添加成功！", "员工已经成功添加", "success");
          this.dialogeditVisible = false;
          this.get_users();
          return;
        }
        this.$swal("添加失败！", res.data.code_desc, "error");
        this.dialogeditVisible = false;
      });
    },
    get_users() {
      this.$api.getCrm.get_user().then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
      });
    },
    sorta(a, b) {
      return b - a;
    },
    formatMoney(value) {
      return value.split(".")[0] + "." + value.split(".")[1].slice(0, 2);
    },
    changePrice(value) {
      this.changePriceFlag = true;
      this.nowPlace = value.title;
      this.timeMsg = value.time_price;
      // console.log(value);
    },
    // 添加
    add() {
      let params = this.edit_form;
      // console.log("comming");
      // console.log(this.edit_form);
      this.$api.getTask.addTaskCate(params).then((res) => {
        if (res.data.code == 200) {
          this.$swal("添加成功！", "任务添加成功添加", "success");
          this.getCate();
        } else {
          this.$swal("出错了！", res.data.result, "error");
        }
        this.dialogFormVisible = false;
      });
    },

    // 编辑
    toedit(item) {
      this.dialogeditVisible = true;
      this.edmsgs = item;
    },

    format(value) {
      let time = new Date(parseInt(value) * 1000);
      // console.log(555,time)
      time =
        time.toLocaleDateString().replace(/\//g, "-") +
        " " +
        time.toTimeString().substr(0, 8);
      return time;
    },
    xzshop(str) {
      if (str == "xzShop") {
        if (
          this.$store.state.shopSlist == "" ||
          this.$store.state.shopSlist.page != 1
        ) {
          this.$store.dispatch("getShopsAll", { page: 1, page_size: 10 });
        }
      }
      this.current = str;
      this.shows = true;
    },
    getShow(val) {
      this.shows = val;
    },
    getSend(row) {
      // console.log(row);
      if (this.current == "xzShop") {
        // console.log(row);
        this.shopinfo = row;
        this.formVideo.pid = row.id;
      }
    },

    editbtn(item) {
      this.edit_form = item;
      this.dialogeditVisible = true;
    },

    addbtn() {},

    rev_send_url(val) {
      this.formVideo.uri = val.url;
    },
    add_data() {
      this.dialogFormVisible = true;
    },
    change_recomment(val, row, type) {
      var params = {};
      params.id = row.id;
      if (type == "recomment") {
        params.is_recommend = val;
      } else {
        params.is_check = val;
      }
      this.$api.getPage.edit_reply_isrecommend(params).then((res) => {
        if (res.data.code == 200) {
          this.$fnc.alertSuccess(res.data.result);
        } else {
          this.$fnc.alertError(res.data.result);
        }
      });
    },
    dia_close() {
      this.playurl = "";
      var x = document.getElementById("videobox");
      x.load();
    },
    showvideo(info) {
      this.dialogFormVisible = true;
      if (info.uri.indexOf("http") < 0) {
        this.playurl =
          "https://inexweb.oss-cn-shenzhen.aliyuncs.com/" + info.uri;
      } else {
        this.playurl = info.uri;
      }
      this.$nextTick(() => {
        var x = document.getElementById("videobox");
        x.load();
      });
    },
    receive_search(obj) {
      // console.log(obj)
      this.searchAll = obj;
      // this.getNewsAll(obj);
      this.getDoTaskList(obj);
    },
    getNewsAll(params) {
      // console.log(1, params);
      // console.log("ccccc");
      params.id = this.$route.query.id;
      this.$api.getTask.getDoList(params).then((res) => {
        if (res.data.code === 200) {
          this.loading = false;
          this.list = res.data.result;
          // console.log(555);
          // console.log(this.list);
        }
      });
    },
    handleSizeChange(val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },

    reload() {
      this.getNewsAll(this.searchAll);
    },
    // 添加图片
    handleRemove(file, fileList) {
      // console.log(file, fileList);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    // 删除
    beforeCreate() {},
  },
};
</script>

<style lang="less" scoped>
.myblank button {
  margin: 5px 5px 0 0;
}

.place {
  margin: 5px 0;
}
.is_item {
  display: flex;
  align-items: flex-end;
  .types {
    div {
      width: 200px;
      margin-right: 10px;
    }
    .input {
      margin: 5px 0px;
    }
    display: flex;
  }
  .btn_edit {
    height: 40px;
    margin-left: 10px;
    margin-bottom: 5px;
  }
}
.know_btn {
  width: 100%;
  display: flex !important;
  justify-content: flex-end !important;
}
</style>
